/**
 * 
 */
package com.etc.user.controller;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.etc.entity.Order;
import com.etc.entity.Room;
import com.etc.user.service.UserOrderService;
import com.etc.util.CommonMessage;
import com.etc.util.OrderMessage;

/**
 * @author ccq
 *
 * date: 2019年5月5日  下午5:15:42
 */
@Controller
public class UserOrderController {
	
	Logger logger = Logger.getLogger(UserOrderController.class);
	
	@Resource(name="userOrderService")
	private UserOrderService userOrderService;
	
	@RequestMapping(value="selectRoom",method=RequestMethod.GET)
	@ResponseBody
	public Map<String, Object> selectRoom(String orderstartdate, String orderenedate, Integer roomtype) {
//		ModelAndView mv = new ModelAndView("users/shortcodes");
		List<Room> rooms = userOrderService.selectRoom(orderstartdate, orderenedate, roomtype);
		Map<String, Object> map=new HashMap<String, Object>();
		map.put("rooms", rooms);
		return map;
	} 
	
	@RequestMapping(value="addUserOrder",method=RequestMethod.POST)
	@ResponseBody
	public CommonMessage addUserOrder(HttpServletResponse response,Integer userid,Integer roomid,String orderstartdate,String orderenedate,String ordertel,String ordermessage) throws IOException {
		
		CommonMessage cm = new CommonMessage();
		
		Order order = new Order();
		if(userid!=null) {
			order.setUserid(userid);
			order.setRoomid(roomid);
			order.setOrderstartdate(orderstartdate);
			order.setOrderenedate(orderenedate);
			order.setOrdertel(ordertel);
			order.setOrdermessage(ordermessage);
			
			int n = userOrderService.addUserOrder(order);

			if(n>0) {
				cm.setMsg("预订成功");
			}else {
				cm.setMsg("预订失败");
			}
			
			
		}else {
			
			cm.setMsg("请先登录");
		}
		
		return cm;
	}
	
	

}
